<?php

class adminComments extends Controller
{
    public function index()
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();
    	Helper::verifySuperAdminLoggedIn();
    	
        // load views
		$comments = $this->model->getAllComments();
        
        require APP . 'views/admin_templates/header.php';
        require APP . 'views/adminComments/index.php';
        require APP . 'views/admin_templates/footer.php';
    }
	
	public function addComment()
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();

        if (isset($_POST["submit_comment"])) {
            $this->model->addComment($_POST["user_id"],$_POST["digital_content_id"],$_POST["comment"],$_POST["status"]);
			
        }

        
        header('location: ' . URL . 'home/index');
    }

	public function deleteComment($comment_id)
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();
        
        if (isset($comment_id)) {
            $this->model->deleteComment($comment_id);
			header('location: ' . URL . 'adminComments');
		
        }
          else {
        header('location: ' . URL . 'adminComments');
		}
    }

	public function editComment($comment_id)
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();

        if (isset($comment_id)) {
            $comment= $this->model->getComment($comment_id);

            require APP . 'views/admin_templates/header.php';
            require APP . 'views/adminComments\edit.php';
            require APP . 'views/admin_templates/footer.php';
        } else {
            header('location: ' . URL . 'adminComments');
        }
    }
    
   
    public function updateComment()
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();

        if (isset($_POST["submit_update_comment"])) {
            $this->model->updateComment($_POST["comment_id"],$_POST["status"]);
        }

        header('location: ' . URL . 'adminComments/index');
    }
	
}
